<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        <input type="text" id="txt">
        <button id="btn">验证</button>
        <p></p>
    </div>
</body>
</html>
<script>
    {
        // const sd = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
        // console.log(sd.test('536984256987456315'));
        const txt = document.querySelector('#txt')
        const btn = document.querySelector('#btn')
        const p = document.querySelector('p')
        btn.onclick = function(){
            // console.log(txt.value);
            // p.innerText = '123'
            const get = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
            // console.log(get.test(`${txt.value}`))
            if(get.test(`${txt.value}`)){
                location.href = 'https://www.baidu.com'
            }else{
                console.log('null');
            }
        }
    }
    // {
    //     const get = /[^12]/
    //     console.log(get.test('222'));
    // }
</script>